package com.hqyj.project.service.impl;

import com.hqyj.project.mapper.EchartMapper;
import com.hqyj.project.service.EchartService;
import com.hqyj.project.utils.CommonResult;
import com.hqyj.project.vo.ResignVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EchartServiceImpl implements EchartService {

    @Autowired
    private EchartMapper echartMapper;


    @Override
    public CommonResult getTurnoverRate() {
        //各部门离职人数
        List<ResignVo> select = echartMapper.select();
        //各部门在职人数
        List<ResignVo> selectCountDeptName = echartMapper.selectCountDeptName();
        List<Double> objects = new ArrayList<>();
        for (int i = 0; i < select.size(); i++) {
            double v = select.get(i).getCount() / selectCountDeptName.get(i).getCount();
            String str = String.format("%.2f",v);
            double v2 = Double.parseDouble(str);
            objects.add(v2);
        }
        return new CommonResult(200,"查询成功",objects);
    }

    @Override
    public CommonResult deptNumberPeople() {

        List<ResignVo> deptCounts = echartMapper.deptNumberPeople();
        if(deptCounts.isEmpty()){
            return new CommonResult(500,"查询失败");
        }
        return new CommonResult(200,"查询成功",deptCounts);
    }
}
